package com.chainyoung.common.http.interceptor;

import com.chainyoung.common.utils.SPUtil;
import com.chainyoung.common.utils.StringUtil;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class AddCookiesInterceptor implements Interceptor {

    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException {

        final Request.Builder builder = chain.request().newBuilder();
        String cookie = SPUtil.getInstance().getString("cookie", "");
        if(!StringUtil.isEmpty(cookie)){
            builder.addHeader("Cookie", cookie);
        }
        return chain.proceed(builder.build());
    }

}